<template>
  <el-button type="primary" @click="show">修改</el-button>
  <el-dialog
    v-model="dialogVisible"
    :show-close="true"
    title="修改数据"
    width="30%"
    draggable
    :append-to-body="true"
    :modal="false"
  >
    <!--递归加载子模块，可以无限加载-->
    <el-form :model="company" label-width="120px" style="width: 500px;">
      <el-form-item label="名称">
        <el-input v-model="company.name" />
      </el-form-item>
      <el-form-item label="地址">
        <el-input v-model="company.address" />
      </el-form-item>
      <el-form-item label="电话">
        <el-input v-model="company.telephone" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">Cancel</el-button>
        <el-button type="primary" @click="dialogVisible = false">
          Confirm
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
  import { ref } from 'vue'
  import { Model } from '../../../lib/main'

  // 获取父组件的状态
  import { getListState } from './_state-data-list'

  const { selection } = getListState() 

  // console.log('state\n', pagerInfo)
  const dialogVisible = ref(false)

  // 创建一个 model
  const company = Model(() => {
    return {
      id: '',
      name: '',
      address: '',
      telephone: ''
    }
  })

  // 打开“窗口”准备修改
  const show = () => {
    dialogVisible.value = true
    if (selection.dataId) {
      company.$state = selection.row
    }
  }

</script>